#include <iostream>

using namespace std;

struct hero
{
    string name;
    int age;
    string sex;
};

void age(struct hero * heroarr, int len)
{
    for (int i = 0; i < len - 1; i++)
    {
        for (int j = 0; j < len - i - 1; j++)
        {
            if(heroarr[j].age > heroarr[j + 1].age)
            {
                struct hero temp = heroarr[j];
                heroarr[j] = heroarr[j + 1];
                heroarr[j + 1] = temp;
            }
        }
    }

    cout << "按年龄从小往大排列：" << endl;
    for (int i = 0; i < len; i++)
    {
        cout << heroarr[i].name << endl;
    }
}

int main(void)
{
    struct hero heroarr[5] =
    {
        {"刘备", 23, "男"},
        {"关羽", 22, "男"},
        {"张飞", 20, "男"},
        {"赵云", 21, "男"},
        {"貂蝉", 18, "女"}
    };

    age(heroarr, 5);

    return 0;
}